package leetcode_core.leetcode_5;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年01月04日 11:53
 */
public class GetRow {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> lastRow = new ArrayList<>();
        lastRow.add(1);
        for(int i = 1;i<=rowIndex;i++){
            int lastSize = lastRow.size();
            List<Integer> thisRow = new ArrayList<>();
            for(int j = 0;j<i+1;j++){
                if(j-1 == -1){
                    thisRow.add(0+lastRow.get(j));
                }else if(j == lastSize){
                    thisRow.add(0+lastRow.get(j-1));
                }else{
                    thisRow.add(lastRow.get(j)+lastRow.get(j-1));
                }
            }
            lastRow = thisRow;
        }
        return lastRow;
    }
}
